<template>
  <div class="container">
      <div class="content">
        <span class="title">内容与图片</span>
        <el-form :model="form" ref="form" label-width="120px" class="form">
            <el-row :gutter="41">
                <el-form-item label="客户端：">
                    {{form.client === '0'? '家庭端': form.client === '1'? '教学端': '家庭和教学端'}}
                </el-form-item>
            </el-row>

            <el-row :gutter="41">
                <el-form-item label="内容：">
                    <div v-html="showFace(form.content)"></div>
                </el-form-item>
            </el-row>

            <el-row :gutter="41">
                <el-form-item label="图片：">
                    <el-col :span="20" v-for="item in form.pic" :key="item"><img :src="item" class="imgDetail"></el-col>
                    <div v-if="form.pic.length<1">--</div>
                </el-form-item>
            </el-row>

            <el-row :gutter="41">
                <el-form-item label="点赞数：">
                    {{form.clickNum || '--'}}
                </el-form-item>
            </el-row>

            <el-row :gutter="41">
                <el-form-item label="评论数：">
                    {{form.commentNum || '--'}}
                </el-form-item>
            </el-row>

            <el-row :gutter="41">
                <el-form-item label="发布时间：">
                    {{form.uploadTime || '--'}}
                </el-form-item>
            </el-row>

            <span class="title">链接或自定义</span>
            <el-row :gutter="41" v-if="form.urlType == '0'">
                <el-row >
                    <el-form-item label="链接名称：">
                        {{form.linkName || '--'}}
                    </el-form-item>
                </el-row>

                <el-row>
                    <el-form-item label="链接：">
                        {{form.link || '--'}}
                    </el-form-item>
                </el-row>
            </el-row>
            <el-row :gutter="41" v-if="form.urlType == '1'">
                <el-row >
                    <el-form-item label="链接名称：">
                        {{form.linkName || '--'}}
                    </el-form-item>
                </el-row>
                <el-row >
                    <el-form-item label="自定义内容：">
                        <div v-html="form.htmlContent"></div>
                    </el-form-item>
                </el-row>
            </el-row>
            <div class="form-item">
                <el-row>
                    <el-col :span="24">
                        <div class="footer">
                            <el-button @click="resetForm()">返回</el-button>
                        </div>
                    </el-col>
                </el-row>
            </div>
        </el-form>
      </div>
  </div>
</template>
<script>
import Tinymce from 'components/Tinymce';
import { getDynamic } from 'api/dynamics';
export default {
    name: 'parcelMangement',
    components: { Tinymce },
    data() {
        return {
            form: {
                client: '', // 客户端 0、家庭端 1、教学端 2、家庭和教学端'
                content: '',
                link: '',
                htmlContent: '', // 自定义内容
                pic: '', // 图片，多张以分号隔开
                urlType: '', // 0、链接 1、自定义内容
                linkName: '', // 链接名称
                clickNum: '', // 点赞数
                commentNum: '', // 评论数
                uploadTime: ''
            },
            tinymceId: 'tinymceId'
        };
    },
    created() {
        this.getImgName();
    },
    methods: {
        resetForm() {
            this.$router.push({path: '/dynamics/dynamics'});
        },
        // 获取动态
        getImgName() {
            getDynamic(this.$route.params.pid).then(res => {
                this.form.client = res.data.content.client;
                this.form.content = res.data.content.content;
                this.form.link = res.data.content.link;
                this.form.htmlContent = res.data.content.htmlContent || '--';
                this.form.pic = res.data.content.pic ? res.data.content.pic.split(';') : [];
                this.form.urlType = res.data.content.urlType;
                this.form.clickNum = res.data.content.clickNum;
                this.form.linkName = res.data.content.linkName;
                this.form.commentNum = res.data.content.commentNum;
                this.form.uploadTime = res.data.content.uploadTime;
            })
        },
        showFace(content) {
            return content?content.replace(/\n/g, '<br/>').replace(/\s/g, '&nbsp;'):'';
        }
    }
};
</script>
<style lang="scss" scoped>
.top-title{
    text-align: center;
    font-size: 18px;
    color: #333;
    height: 72px;
    line-height: 72px;
    font-weight: bold;
    border-bottom: 1px solid #ddd;
}
.container {
  position: relative;
  overflow: hidden;
  box-shadow: 0px 0px 5px 0px rgba(0, 0, 0, 0.1);
    -webkit-box-shadow: 0px 0px 5px 0px rgba(0, 0, 0, 0.1);
  .content {
    position: relative;
    padding: 8px 50px 100px;
    background: #fff;
    box-shadow: 0px 0px 5px 0px rgba(0, 0, 0, 0.1);
    -webkit-box-shadow: 0px 0px 5px 0px rgba(0, 0, 0, 0.1);
    .title {
      position: relative;
      font-size: 14px;
      color: rgb(106, 85, 72);
      padding-left: 14px;
      margin: 30px 0;
      display: block;
      &::after {
        position: absolute;
        content: "";
        width: 4px;
        height: 14px;
        background: #ff5e2c;
        left: 0;
        top: 4px;
      }
    }
  }
  .box{
        margin-top:20px;
    }
    .imgDetail{
        display: block;
        max-width: 100%;
    }
    .footer{
        text-align: center;
        padding-top:40px;
    }
}
</style>
